//
//  HMVisitorView.m
//  微博app--OC
//
//  Created by xmy on 16/8/31.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "HMVisitorView.h"
#import "Masonry.h"

@interface HMVisitorView ()

@property(nonatomic,strong)UIImageView *circleView;
@property(nonatomic,strong)UIImageView *maskView;
@property(nonatomic,strong)UIImageView *houseView;
@property(nonatomic,strong)UIButton *loginBtn;
@property(nonatomic,strong)UIButton *registBtn;
@property(nonatomic,strong)UILabel *massageLabel;

//@property(nonatomic,copy)NSString *house;
//@property(nonatomic,copy)NSString *massage;

@end
@implementation HMVisitorView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}
//提供方法共外界调用
- (void)visitorViewInfo:(NSString *)imageName massage:(NSString *)massage{
    if ([imageName  isEqual: @"visitordiscover_feed_image_house"]){
        self.houseView.image = [UIImage imageNamed:imageName];
        
        self.massageLabel.text = massage;
        
        [self circle];
    }else{
        
        self.houseView.image = [UIImage imageNamed:imageName];
        
        self.massageLabel.text = massage;
        
        self.circleView.hidden = YES;
    }
    
    
}

//图片转圈
- (void)circle{

    CABasicAnimation *amin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
    amin.toValue = [NSNumber numberWithDouble:M_PI * 2];
    
    amin.duration = 20;
    
    amin.removedOnCompletion = false;
    
    amin.repeatCount = CGFLOAT_MAX;
    
    [self.circleView.layer addAnimation:amin forKey:nil];
    
}
- (void)setup{
    self.backgroundColor = [UIColor colorWithWhite:237.0/255 alpha:1];
    
    //添加到视图
    [self addSubview:self.circleView];
    [self addSubview:self.maskView];
    [self addSubview:self.houseView];
    [self addSubview:self.massageLabel];
    [self addSubview:self.registBtn];
    [self addSubview:self.loginBtn];
    
    //构建约束
    //转圈
    [self.circleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    
    //房子
    [self.houseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.circleView);
    }];
    
    //消息
    [self.massageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.houseView.mas_bottom).offset(16);
        make.centerX.equalTo(self.houseView);
        make.width.offset(224);
    }];
    
    //注册
    [self.registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.massageLabel.mas_bottom).offset(16);
        make.left.equalTo(self.massageLabel);
        make.width.offset(100);
        make.height.offset(35);
    }];
    
    //登录
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.registBtn);
        make.right.equalTo(self.massageLabel);
        make.width.offset(100);
        make.height.offset(35);
    }];

    //遮罩
    [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.bottom.equalTo(self.registBtn);
    }];
    
    
}

//懒加载
//转圈图片
-(UIImageView *)circleView{
    if(!_circleView){
        _circleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    }
    return _circleView;
}
//遮罩
-(UIImageView *)maskView{
    if(!_maskView){
        
      _maskView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];

    }
    return _maskView;

}
//房子
-(UIImageView *)houseView{
    if(!_houseView){
        _houseView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _houseView;
}
//信息
-(UILabel *)massageLabel{
    if(!_massageLabel){
        _massageLabel = [[UILabel alloc]init];
        _massageLabel.text = @"哈哈哈哈哈哈哈";
        _massageLabel.font= [UIFont systemFontOfSize:14];
        _massageLabel.textColor = [UIColor darkGrayColor];
        _massageLabel.numberOfLines = 0;
        _massageLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _massageLabel;
}
//注册
-(UIButton *)registBtn{
    if(!_registBtn){
        
        _registBtn = [[UIButton alloc]init];
        [_registBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white"] forState:UIControlStateNormal];
        [_registBtn setTitle:@"注册" forState:UIControlStateNormal] ;
        
        _registBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_registBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    }
    return _registBtn;
}
//登录
-(UIButton *)loginBtn{
    if(!_loginBtn){
        _loginBtn = [[UIButton alloc]init];
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white"] forState:UIControlStateNormal];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal] ;
        
        _loginBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_loginBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];

    }
    return _loginBtn;
}
@end
